home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
PublicDomain
/
Goldies
/
PolyEd2
/
Macros
/
blockformat.ped
next >
Wrap
Text File
|
1999-11-08
|
4KB
|
168 lines
/*
** $VER: blockformat.ped 1.0 (6.5.95) written by Stefan Schulz
** bases on format.ped by Robert Brandner
**
** This macro formats the current paragraph as justified block
** (from the current line to the next line starting with a space).
*/
OPTIONS RESULTS
OPTIONS FAILAT 11 /* ignore warnings */
SIGNAL ON SYNTAX /* ensure clean exit */
SIGNAL ON FAILURE
SIGNAL ON BREAK_C /* no label->syntax->exit */
if (LEFT(ADDRESS(), 6) ~= "POLYED") then do
if SHOW("Ports", "POLYED.1") then
address 'POLYED.1'
else do
say "PolyEd is not running!"
exit
end
end
'LOCKGUI'
/*----- begin of custom code area --------------------------------------*/
'GETATTR' APPLICATION STEM APP. /* get all infos on app. */
'GETATTR' PROJECT APP.CURRENTPROJECT STEM PROJ. /* get infos on project */
'GETCURSORPOS' STEM CP. /* current line */
/* now we get all lines until we reach a line starting with space or
** the end of the text, and join them in a buffer (with a space in
** between).
** While doing that, we mark all the lines we put into the buffer.
*/
BUFFER = ""
LINECOUNTER = CP.LINE
'POSITION SOL' /* Keep starting Spaces */
'POSITION EOW' /**/
'POSITION SOW' /**/
'GETCURSORPOS' STEM STARTPOS.
'BLOCK START'
'GETLINE' VAR 'LINE'
LINE = strip( LINE, B, " " || '09'X )
if length(LINE) > 0
then do
BUFFER = BUFFER || " " || LINE
'CURSOR DOWN'
'POSITION SOL'
do forever
'GETLINE' VAR 'LINE'
if (length(LINE) = 0) | (left(LINE,1) = ' ') then leave
LINE = strip(LINE, B, " "||'09'X)
BUFFER = BUFFER || " " || LINE
'CURSOR DOWN'
LINECOUNTER = LINECOUNTER+1 /* increment linecounter */
if LINECOUNTER > PROJ.LINES
then do
'POSITION EOL' /* mark last line too */
leave
end
end
end
'ERASE' /* erase the marked area */
'SETATTR APPLICATION FIELD FLAG_AUTOINDENT NEWVALUE 0'
/* Now we write out the buffer again.
** To be faster we create a complete line internally
** instead of writing each single word.
*/
len = STARTPOS.COLUMN - 1 /* add leading spaces */
numwords = words(BUFFER) /* #words in buffer */
do i = 1 to numwords
/* collect words until line is full */
cnt = 0
line = ""
do j = i to numwords
w = word(BUFFER,j)
wlen = length(w)
if (len + wlen) >= APP.VAR_RIGHTBORDER then leave j
if length(line) = 0
then line = w
else line = line || " " || w
len = len + wlen + 1
cnt = cnt + 1
if j = numwords then leave i
end
if cnt > 0 then cnt = cnt - 1
/* fill line with spaces. Start with punctuation marks. */
nPos = length(line)
cmp = '. '
do j = 0 while len < APP.VAR_RIGHTBORDER
nPos = lastpos( cmp, line, nPos - 1 )
if nPos = 0
then do
select
when cmp = '. ' then cmp = '! '
when cmp = '! ' then cmp = '? '
when cmp = '? ' then cmp = '; '
when cmp = '; ' then cmp = ': '
when cmp = ': ' then cmp = ', '
otherwise leave j
end
nPos = length(line)
end
else do
line = left(line, nPos) || ' ' || right(line, length(line) - nPos)
len = len + 1
end
end
/* add spaces to line behind each word, if line still to short */
nPos = 0
inc = 3
do j = 0 while len < APP.VAR_RIGHTBORDER
nPos = pos( ' ', line, nPos + inc )
if nPos = 0
then inc = inc + 1
else do
line = left(line, nPos) || ' ' || right(line, length(line) - nPos)
len = len + 1
end
end
i = i + cnt
len = 0
'TEXT' line
'TEXT NEWLINE'
end
'TEXT' line
'TEXT NEWLINE'
'SETATTR APPLICATION FIELD FLAG_AUTOINDENT NEWVALUE' APP.FLAG_AUTOINDENT
/*----- end of custom code area ----------------------------------------*/
'UNLOCKGUI' /* Clean exit */
EXIT
SYNTAX: /* ARexx error... */
say "Error line" SIGL ":" ERRORTEXT(RC) /* report it... */
'UNLOCKGUI' /* Unlock GUI! */
EXIT /* exit */
FAILURE:
'UNLOCKGUI' /* Unlock GUI! */
EXIT /* exit */